<template>
  <div>
    <h1>等你妈的路</h1>
    <p>账号：<input type="text" v-model="form.username"></p>
    <p>密码：<input type="text" v-model="form.password"></p>
    <button @click="login">登录</button>
    <button @click="dd">微信登录</button>

  </div>
</template>

<script>
export default {
  name: "login",
  data() {
    return {
      form: {},
    }
  },
  methods: {
    dd() {
      // this.$axios.post('/login/sfM',{'uid':this.uid,'token':this.token}).then(res=>{
      //   if(res.data.code==200){
      //     alert('ok')
      //     localStorage.setItem('userid',res.data.userid)
      //     this.$router.push('/')
      //   }else {
      //     window.location.href = res.data.url
      //   }
      // })
      this.$axios.get('/login/uidtoken').then(res => {
        if (res.data.code == 200) {
          localStorage.setItem('uid',res.data.uid)
          localStorage.setItem('ltoken',res.data.ltoken)
          this.$axios.post('/login/sfM',{'uid':localStorage.getItem('uid'),'token':localStorage.getItem('ltoken')})
          .then(re=>{
          if(re.data.code==200){
          alert('登录成功')
          localStorage.setItem('userid',re.data.userid)
          window.location.href = re.data.url
          }
          else {
          window.location.href = re.data.url
          }
          })
        }


      })
    },


    login() {
      this.$axios.post('/login/login', this.form).then(res => {
        if (res.data.code == 200) {
          alert('登录成功')
          localStorage.setItem('userid', res.data.userid)
          localStorage.setItem('username', res.data.username)
          this.$router.push('/')
        } else {
          alert(res.data.mes)
        }

      })
    }


  }
}
</script>

<style scoped>

</style>
